<template>
	<view class="logon">
		<view class="list">
			<view class="list-call">
				<input class="phone" type="number" v-model="phone" maxlength="11" placeholder-style="color:#CCCCCC" placeholder="请输入手机号" />
			</view>
			<view class="list-call">
				<input class="biaoti" type="text" password v-model="pwd" maxlength="32" placeholder-style="color:#CCCCCC"
				 placeholder="请输入密码" :password="!showPassword" />
				<image class="img" :src="showPassword?'../../static/images/op.png':'../../static/images/cl.png'" @tap="display"></image>
			</view>
		</view>
		<!-- <view class="btn" @tap="login">
			登录
		</view> -->
		<button open-type="getUserInfo" class="btn"   @tap="weixinLoin">登录</button>
		<view class="uni-text">
			<text @tap="resetPwd">忘记密码</text>
			<text @tap="goPhoneCode">验证码登录</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showPassword:false,
				phone:"",
				pwd:""
			}
		},
		methods: {
			display(){
				this.showPassword = !this.showPassword
			},
			goPhoneCode(){
				uni.redirectTo({
				    url: '/pages/login/phoneCodeLogin'
				});
			},
			weixinLoin(e){
				let _this = this;
				if(this.phone.length == 0){
					uni.showToast({
						title:"手机号码不能为空",
						icon:"none"
					})
					return false
				}
				if(!(/^1[3456789]\d{9}$/.test(this.phone))){
							uni.showToast({
								 title: '请输入正确得手机号',
								 icon: 'none'
							})
					        return false; 
				}
				if(this.pwd.length == 0){
					uni.showToast({
						title:"密码不能为空",
						icon:"none"
					})
					return false
				}
				uni.login({
				  provider: _this.loginProvider,
				  success: function (loginRes) {
				    console.log(loginRes);
					let data = {
						code:loginRes.code,
						"mobile": _this.phone,
						"password": _this.pwd,
					}
					_this.$http.post('/api/v1.0/appletMobileLogin',data,res=>{
						if(res.data.status == '000000'){
							uni.setStorage({
								key:'userId',
								data:res.data.data.userId,
							})
							uni.setStorage({
								key:'token',
								data:res.data.data.token,
							})
							uni.setStorage({
								key:'nickName',
								data:res.data.data.nickName,
							})
							uni.setStorage({
								key:'buyerAccountId',
								data:res.data.data.buyerAccountId,
							})
							uni.setStorage({
								key:'userLogo',
								data:res.data.data.logo,
							})
							uni.setStorage({
								key:'phone',
								data:res.data.data.mobile,
							})
							uni.switchTab({
								url:'/pages/index/index'
							})
						}else if(res.data.status == '009001' || res.data.status == '009123'){
							uni.showToast({
								title:'账号或密码错误！',
								icon:"none"
							})
						}else if(res.data.status == '009124'){ 
							uni.showToast({
								title:'当前登录账号与绑定手机号不一致！',
								icon:"none"
							})
						}else{
							uni.showToast({
								title:'服务器开小差了！',
								icon:"none"
							})
						}
						
						
					})
				  }
				});
				
			},
			resetPwd(){
				uni.navigateTo({
					url:'../register/resetPwd'
				})
			}
		}
	}
</script>

<style lang="scss">
	.list {
		display: flex;
		margin-top: 70upx;
		flex-direction: column;
		padding-top: 50upx;
		padding-left: 70upx;
		padding-right: 70upx;

		.list-call {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			height: 100upx;
			color: #333333;
			font-size: 28upx;
			border-bottom: 1upx solid rgba(217,217,217,1);

			.img {
				width: 40upx;
				height: 40upx;
			}
			.phone{
				padding-left: 16upx;
			}
			.biaoti {
				flex: 1;
				text-align: left;
				line-height: 100upx;
				padding-left: 16upx;
			}
		}
	}
	.btn{
		width:616upx;
		height:88upx;
		background:linear-gradient(360deg,rgba(227,67,57,1) 0%,rgba(249,98,58,1) 100%);
		border-radius:20upx;
		font-size:36upx;
		color:rgba(255,255,255,1);
		display: flex;
		justify-content: center;
		align-items: center;
		margin: 50upx auto 30upx;
	}
	.uni-text{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		padding:0 70upx;
		font-size:24upx;
		font-weight:500;
		color:rgba(77,77,77,1);
	}
</style>
